package prepare.huawei;

import java.util.Scanner;

/**
 * description: <a href="https://blog.csdn.net/qfc_128220/article/details/127228559">字符串序列判定</a>
 *
 * @author <a href="zhaoyingling12@163.com">simon zhao</a>
 * @since 2023/3/25
 */
public class StringSequenceDetermination {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        char[] sChars = input.nextLine().toCharArray();
        char[] lChars = input.nextLine().toCharArray();
        // 用 index 表示 s 与 l 已经匹配的位置
        int index = -1;
        for (int i = 0; i < lChars.length; i++) {
            if (sChars[index + 1] == lChars[i]) {
                index++;
            }
            // 输出s串中最后一个字符在L中的位置
            if (index == sChars.length - 1) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}
